package com.gxa.modules.pc.fee.controller;

import com.gxa.common.utils.FilePortUtil;
import com.gxa.common.utils.PageUtils;
import com.gxa.common.utils.Result;
import com.gxa.modules.model.dto.*;
import com.gxa.modules.model.entity.fee.InOrderDetail;
import com.gxa.modules.model.entity.fee.Patient;
import com.gxa.modules.pc.fee.service.InpatientConsumptionRecordsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
 * <p>
 * 住院消费记录表 前端控制器
 * </p>
 *
 * @author gxa
 * @since 2022-11-12 05:31:54
 */
@Api(tags = "住院消费记录表")
@RestController
@RequestMapping("/inpatient-consumption-records")
public class InpatientConsumptionRecordsController {

    @Autowired
    private InpatientConsumptionRecordsService inpatientConsumptionRecordsService;

    @PostMapping("/list")
    @ApiOperation("住院消费记录表分页查询")
    @ApiResponses({
            @ApiResponse(code = 0,message = "success", response = InpatientConsumptionRecordsDto.class)
    })
    public Result list(@RequestBody RefundSearchDto refundSearchDto){
        try {
            PageUtils pageUtils = this.inpatientConsumptionRecordsService.queryListSearch(refundSearchDto);
            return new Result().ok(pageUtils);
        }catch (Exception e){
            e.printStackTrace();
            return new Result().error("查询失败");
        }
    }

    @PostMapping("/list/{patientId}/{inInfoId}/{inOrderId}")
    @ApiOperation("住院消费记录表详细信息查询")
    @ApiResponses({
            @ApiResponse(code = 0,message = "success", response = Patient.class),
            @ApiResponse(code = 0,message = "success", response = DetailInfoDto2.class),
            @ApiResponse(code = 0,message = "success", response = InOrderDetail.class),
            @ApiResponse(code = 0,message = "success", response = MedicineDto.class)
    })
    public Result listInfo(@RequestParam("patientId") Integer patientId, @RequestParam("inInfoId") Integer inInfoId, @RequestParam("inOrderId") Integer inOrderId){
        try {
            Map<String, Object> map = this.inpatientConsumptionRecordsService.queryInfo(patientId, inInfoId, inOrderId);
            return new Result().ok(map);
        }catch (Exception e){
            e.printStackTrace();
            return new Result().error("查询失败");
        }
    }

    @GetMapping(value = "/fileport")
    @ApiOperation("导出退款记录表")
    public void filePort(HttpServletResponse response) {
        //导出的表名
        String title = "导出住院消费记录";
        //表中第一行表头字段
        String[] headers = {"主键id", "操作时间", "订单号", "患者姓名", "住院号", "来源", "业务类型", "支付方式：0微信支付，1住院预交金扣费", "支付金额", "缴费状态"};
        //实际数据结果集
        List<InpatientConsumptionRecordsDto> inpatientConsumptionRecordsDtoList = this.inpatientConsumptionRecordsService.queryList();
        //具体需要写入excel需要哪些字段，这些字段取自RechargeDetailRecordDto类，也就是上面的实际数据结果集的泛型
        List<String> listColumn = Arrays.asList("id", "createTime", "inOrderId", "name", "inpatientNum", "source", "type", "peyMethod", "orderTotal", "status");
        try {
            FilePortUtil.exportExcel(response, title, headers, inpatientConsumptionRecordsDtoList, listColumn);
        } catch (Exception e) {
            e.printStackTrace();
        }

    }


}
